package com.example.springboot.utils.vo;

import com.wbs.utls.FastJsonUtils;
import com.wbs.utls.constant.QueueConstant;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wangsh
 * @date 2019/8/9 16:14
 * @Description
 */
public class MQRestRstDataUtils {


    public static String put(int count, String msg, String messageId) {
        //发送缓存数据
        MQRestRstDta rstDta = new MQRestRstDta(1, msg, messageId);
        ConcurrentHashMap<String, MQRestRstDta> map = new ConcurrentHashMap<>();
        map.put(QueueConstant.RESUME_KEY, rstDta);
        return FastJsonUtils.toJSONString(map);
    }

    public static MQRestRstDta get(String mqData, String messageId) {
        MQRestRstDta rstDta = FastJsonUtils.jsonToBean(mqData, MQRestRstDta.class);
        rstDta.setCount(rstDta.getCount() + 1);
        return rstDta;
    }


    public static String set(Map map, String messageId) {

        String mqData = map.get(messageId).toString();
        MQRestRstDta rstDta = FastJsonUtils.jsonToBean(mqData, MQRestRstDta.class);
        rstDta.setCount(rstDta.getCount() + 1);
        map.put(QueueConstant.RESUME_KEY, rstDta);

        return FastJsonUtils.toJSONString(map);
    }

    public static String remove(Map map, String messageId) {

        map.remove(messageId);
        return FastJsonUtils.toJSONString(map);
    }

}
